<?php

namespace App\Policies;

use App\Models\House;
use App\Models\Admin;
use Illuminate\Auth\Access\HandlesAuthorization;
use PermissionService;
use Illuminate\Auth\Access\Response;

class HousePolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the  can view any models.
     *
     * @param \App\Models\ $admin
     * @return \Illuminate\Auth\Access\Response|bool
     */


    public function viewAny(Admin $admin)
    {
        return (PermissionService::access('house-index') || $admin->id == 1) ? Response::allow()
            : Response::deny('您没有操作权限，请联系管理员');
    }

    /**
     * Determine whether the Admin can view the model.
     *
     * @param \App\Models\Admin $admin
     * @param \App\Models\House $house
     * @return \Illuminate\Auth\Access\Response|bool
     */
    public function view(Admin $admin, House $house)
    {
        //
    }

    /**
     * Determine whether the Admin can create models.
     *
     * @param \App\Models\Admin $admin
     * @return \Illuminate\Auth\Access\Response|bool
     */
    public function create(Admin $admin)
    {
        return (PermissionService::access('house-create') || $admin->id == 1) ? Response::allow()
            : Response::deny('您没有操作权限，请联系管理员');
    }

    /**
     * Determine whether the Admin can update the model.
     *
     * @param \App\Models\Admin $admin
     * @param \App\Models\House $house
     * @return \Illuminate\Auth\Access\Response|bool
     */
    public function update(Admin $admin, House $house)
    {
        return (PermissionService::access('house-create') || $admin->id == 1) ? Response::allow()
            : Response::deny('您没有操作权限，请联系管理员');
    }

    /**
     * Determine whether the Admin can delete the model.
     *
     * @param \App\Models\Admin $admin
     * @param \App\Models\House $house
     * @return \Illuminate\Auth\Access\Response|bool
     */
    public function delete(Admin $admin, House $house)
    {
        return (PermissionService::access('house-index') || $admin->id == 1) ? Response::allow()
            : Response::deny('您没有操作权限，请联系管理员');
    }

    /**
     * Determine whether the Admin can restore the model.
     *
     * @param \App\Models\Admin $admin
     * @param \App\Models\House $house
     * @return \Illuminate\Auth\Access\Response|bool
     */
    public function restore(Admin $admin, House $house)
    {
        //
    }

    /**
     * Determine whether the Admin can permanently delete the model.
     *
     * @param \App\Models\Admin $admin
     * @param \App\Models\House $house
     * @return \Illuminate\Auth\Access\Response|bool
     */
    public function forceDelete(Admin $admin, House $house)
    {
        //
    }
}
